'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 装备
 * @author sundbcn@gmail.com (sun debing)
 */

var mongoose = require('mongoose');
var _ = require('lodash');
var itemUtil = require('../../util/itemUtil');
var genEquipService = require('../../services/genEquipService');
var dataApi = require('../../libs/dataApi');
var equipConf = require('../../config/equipConf');

///////////////////////////////////////////////////////////
/**
 * 装备
 * @type {mongoose}
 */
var bagEquipSchema = new mongoose.Schema({
    /// 装备id
    equip_id: {
        type: Number,
        required: true,
        index: true
    },

    // 装备类型
    equip_type: {
        type: Number,
        required: true
    },

    // 强化等级
    lv: {
        type: Number,
        default: 0
    },

    // 是否可以进阶  1 可以进阶     0 不可进阶
    is_advanced: {
        type: Number,
        default: 0
    },

    // 精炼等级
    refine_lv: {
        type: Number,
        default: 0
    },
});

/**
 * 设置装备是否可进阶   PS: 1 可进阶      0 不可进阶
 * @return {[type]} [description]
 */
bagEquipSchema.methods.setAdvanced = function (value) {
    this.is_advanced = value;
};

/**
 * 装备类型
 * @return {[type]} [description]
 */
bagEquipSchema.methods.getType = function () {
    return this.equip_type;
};

/**
 * 修改装备类型
 * @return {[type]} [description]
 */
bagEquipSchema.methods.setType = function (new_equip_type) {
    this.equip_type = new_equip_type;
};

/**
 * 获取部位类型
 * @return {[type]} [description]
 */
bagEquipSchema.methods.getPartType = function () {
    return itemUtil.getEquipPartType(this.equip_type);
};

/**
 * 装备id
 * @return {[type]} [description]
 */
bagEquipSchema.methods.getId = function () {
    return this.equip_id;
};

/**
 * 装备强化等级
 */
bagEquipSchema.methods.getLv = function () {
    return this.lv;
};

/**
 * 设置强化等级
 * @return {[type]} [description]
 */
bagEquipSchema.methods.setLv = function (new_lv) {
    this.lv = new_lv;
};

/**
 * 精炼等级
 * @return {[type]} [description]
 */
bagEquipSchema.methods.addRefineLv = function () {
    this.refine_lv++;
};

/**
 * 一键精炼等级
 * @return {[type]} [description]
 */
bagEquipSchema.methods.setRefineLv = function (lv) {
    this.refine_lv = lv;
};

/**
 * 获取精炼等级
 * @return {[type]} [description]
 */
bagEquipSchema.methods.getRefineLv = function () {
    return this.refine_lv;
};

/**
 * 升级
 */
bagEquipSchema.methods.upgrade = function () {
    this.lv++;
};

/**
 * 降级
 * @return {[type]} [description]
 */
bagEquipSchema.methods.degrade = function () {
    if (this.lv <= 0) {
        return false;
    }
    this.lv--;
    return true;
};

if (!bagEquipSchema.options.toJSON) {
    bagEquipSchema.options.toJSON = {};
}
/* jshint unused:false */
bagEquipSchema.options.toJSON.transform = function (doc, ret) {
    delete ret._id;
};

module.exports = bagEquipSchema;
